// 利用generator的惰性求值，实现斐波那契函数比较简单

function* fibs() {
    let a = 0;
    let b = 1;
    while (true) {
        yield a;
        [a, b] = [b, a + b]
    }
}

function test() {
    const [one, two, three] = fibs() // 生成器解构赋值
    console.log(one, two, three);

    // 循环取值
    let n = 10
    const gen = fibs()
    while(n--) {
        console.log(gen.next().value)
    }
}


test()